/*
 * file-name shared_hashmap_create.cc
 *
 * date 2019-4-5
 *
 * desc create hashmap in shared memory
 */

#include <iostream>
#include <unordered_map>
#include <string>
#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <unistd.h>
#include <cstdlib>

int main()
{
  key_t key = ftok("./", 66);
  if(key == -1)
  {
    perror("ftok");
    return 1;
  }

  int shmid = shmget(key, 4096, IPC_CREAT|IPC_EXCL|0666); 
  if(shmid == -1)
  {
    perror("shmget");
    return 2;
  }
  
  void* addr = nullptr;
  addr = shmat(shmid, 0, 0);
  if((void*)-1 == addr)
  {
    perror("shmat");
    return 3;
  }

  std::unordered_map<std::string, std::string>* pmap = nullptr;
  pmap = (std::unordered_map<std::string, std::string>*)addr;


  
  return 0;
}

